import request from '@/utils/request';
import { AxiosPromise } from 'axios';
import {
  DictTypeQuery,
  DictTypePageResult,
  DictTypeForm,
  DictQuery,
  DictForm,
  // DictPageResult
} from './types';

/**
 * 字典类型分页列表
 *
 * @param queryParams
 */
export function getDictTypePage(
  queryParams: DictTypeQuery
) {
  return request({
    url: '/api/sys/dict/list',
    method: 'post',
    data: queryParams
  });
}

/**
 * 字典类型表单数据
 *
 * @param id
 */
export function getDictTypeForm(id: number): AxiosPromise<DictTypeForm> {
  return request({
    url: '/api/v1/dict/types/' + id + '/form',
    method: 'get'
  });
}

/**
 * 新增字典类型
 *
 * @param data
 */
export function addDictType(data: DictTypeForm) {
  return request({
    url: '/api/sys/dict/add',
    method: 'post',
    data: data
  });
}

/**
 * 修改字典类型
 *
 * @param id
 * @param data
 */
export function updateDictType(data: DictTypeForm) {
  return request({
    url: '/api/sys/dict/update',
    method: 'post',
    data: data
  });
}

/**
 * 删除字典类型
 */
export function deleteDictTypes(id: number) {
  return request({
    url: '/api/sys/dict/type/delete',
    method: 'post',
    data: {
      id
    }
  });
}
/**
 * 批量删除字典类型
 */
export function deleteListDictTypes(ids: number[]) {
  return request({
    url: '/api/sys/dict/delete',
    method: 'post',
    data: {
      ids
    }
  });
}


/**
 * 获取字典类型的数据项
 *
 * @param typeCode 字典类型编码
 */
export function getDictOptions(typeCode: string): AxiosPromise<OptionType[]> {
  return request({
    url: '/api/v1/dict/types/' + typeCode + '/items',
    method: 'get'
  });
}

/**
 * 子字典分页列表
 */
export function getDictPage( data: any ) {
  return request({
    url: '/api/sys/dictChilden/list',
    method: 'post',
    data
  });
}

/**
 * 获取字典表单数据
 *
 * @param id
 */
export function getDictFormData(id: number) {
  return request({
    url: '/api/v1/dict/' + id + '/form',
    method: 'get'
  });
}

/**
 * 新增子字典
 *
 * @param data
 */
export function addDict(data: DictForm) {
  return request({
    url: '/api/sys/dictChilden/add',
    method: 'post',
    data: data
  });
}

/**
 * 修改子字典
 *
 * @param id
 * @param data
 */
export function updateDict(data: DictForm) {
  return request({
    url: '/api/sys/dictChilden/update',
    method: 'post',
    data: data
  });
}
/**
 * 批量删除子字典
 *
 * @param ids 数组[]
 */
export function deleteListDict(ids: number[]) {
  return request({
    url: '/api/sys/dictChilden/delete',
    method: 'post',
    data: {
      ids
    }
  });
}


